package com.text.lambda;

import java.util.*;
import java.util.stream.Collectors;

public class LambadaDemo {
    //	() -> System.out.println("Hello Lambda Expressions");
//	new Thread(()->System.out.println("In Java8, Lambda expression rocks !!") ).start();
    public static void main(String[] args) {
        //案例1
//		List<Integer> numbers= Arrays.asList(1,2,3,4,5,6,7,8,9,10);
//		numbers.stream()
//		.filter(e -> e % 2 ==0)
//		.forEach(e -> System.out.println(e));
        //案例2：lambada实现runnable
        new Thread(() -> System.out.println("asdfasdfsd asdfasd")).start();
        //案例3：遍历
        List feature = Arrays.asList("lambda", "default", "Strean", "Date and time");
//		feature.forEach(n-> System.out.println(n));
        //双冒号的使用
        feature.forEach(System.out::println);
        //案例4：集合排序
        String[] players = {"Rafael Nadal", "Novak Djokovic",
                "Stanislas Wawrinka", "David Ferrer",
                "Roger Federer", "Andy Murray",
                "Tomas Berdych", "Juan Martin Del Potro",
                "Richard Gasquet", "John Isner"};
        Comparator<String> sortByName = (String s1, String s2) -> (s1.compareTo(s2));
        List<Test> list = new ArrayList<Test>();
        Test a = new Test();
        a.setAaa("aa");
        Test b = new Test();
        b.setAaa("aa");
        Test c = new Test();
        c.setAaa("bb");
        list.add(a);
        list.add(b);
        list.add(c);
        Map<String, List<Test>> collect = list.stream().filter(p->p.getAaa().equalsIgnoreCase("aa")).collect(Collectors.groupingBy(p->p.getAaa()));
        Arrays.sort(players, sortByName);
        for (int i = 0; i < players.length; i++) {
            System.out.println(players[i]);
        }


    }
}